import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import vo.Dept;
import vo.Emp;
import vo.Stu;
import vo.Student;

import java.io.InputStream;
import java.util.List;

public class IbatisTest01 {
    public static void main(String[] args) throws Exception {
        //使用文件流加载mybatis的数据库连接文件
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        //获取该文件中的数据库连接配置，生成数据库的连接工厂
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        //获取一个数据库的连接 ，类似与Connection
        SqlSession session = factory.openSession();

        //从mapper的映射文件中 获取声名的SQl语句   命名空间+声名的sql语句
        //List<Stu> list = session.selectList("com.mapper.StudentMapper.selectAllStu");
        List<Student> list = session.selectList("com.mapper.StudentMapper.selectAllStudent");
        for (Student s : list) {
            System.out.println(s.toString());
        }

        List<Emp> list1 = session.selectList("selectEmp");
        for (Emp e : list1) {
            System.out.println(e.toString());
        }

        List<Emp> list2 = session.selectList("selectEmp2");
        for (Emp e : list2) {
            System.out.println(e.toString2());
        }

        List<Emp> list3 = session.selectList("selectEmp3");
        for (Emp e : list3) {
            System.out.println(e.toString3());
        }

        List<Emp> list4 = session.selectList("selectEmp4");
        for (Emp e : list4) {
            System.out.println(e.toString4());
        }

        List<Emp> list5 = session.selectList("selectEmp5");
        for (Emp e : list5) {
            System.out.println(e.toString5());
        }

        List<Emp> list6 = session.selectList("selectEmp6");
        for (Emp e : list6) {
            System.out.println(e.toString6());
        }

        List<Emp> list7 = session.selectList("selectEmp7");
        for (Emp e : list7) {
            System.out.println(e.toString7());
        }

        List<Emp> list8 = session.selectList("selectEmp8");
        for (Emp e : list8) {
            System.out.println(e.toString8());
        }

        List<Emp> list9 = session.selectList("selectEmp9");
        for (Emp e : list9) {
            System.out.println(e.toString9());
        }

        List<Emp> list10 = session.selectList("selectEmp10");
        for (Emp e : list10) {
            System.out.println(e.toString10());
        }
        session.close();
    }
}
